<template>
  <div>
    <el-row>
      <div :class="bool?'ishidden':'hiddened'">
        <el-button type="primary" id="user_2" class="iconfont el-icon-useryonghu" @click="handseatuser"></el-button>
        <el-button type="primary" icon="el-icon-search" @click="handleseach"></el-button>
        <el-button type="primary" id="user_3" icon="el-icon-plus" @click="handleLink"></el-button>
      </div>
      <div :class="storebool?'ishidden':'hiddened'">
        <el-button type="primary" id="store_27" @click="addstore">新增门店</el-button>
      </div>
      <div :class="shopbool?'ishidden':'hiddened'">
        <el-button type="primary">添加座位</el-button>
        <el-button type="primary">类别配置</el-button>
      </div>
      <div :class="packagebool?'ishidden':'hiddened'">
        <el-button type="primary" id="sell_16" @click="screend">筛选</el-button>
        <el-button type="primary" id="sell_15" @click="addmeal">新增套餐</el-button>
      </div>
      <div :class="memberbool?'ishidden':'hiddened'">
        <el-button type="primary" id="platRole_2" @click="addrole">添加角色</el-button>
      </div>
      <div :class="rechargebool?'ishidden':'hiddened'">
        <el-button type="primary" id="sell_19" @click="addgrade">新增充值档次</el-button>
      </div>
      <div :class="guidebool?'ishidden':'hiddened'">
        <el-button type="primary" id="system_3" @click="addguide">新增帮助</el-button>
      </div>
      <div :class="typebool?'ishidden':'hiddened'">
        <el-button type="primary" id="system_20" @click="addtype">新增类别</el-button>
      </div>
      <!-- <div :class="targetbool?'ishidden':'hiddened'">
        <el-button type="primary" @click="addcont">新增</el-button>
      </div> -->
      <div :class="bannerbool?'ishidden':'hiddened'">
        <el-button type="primary" id="system_8" @click="addbannerlist">新增轮播图</el-button>
      </div>
      <div :class="refreshmbool?'ishidden':'hiddened'">
        <el-button type="primary" id="system_35" @click="refreshs">刷新美团授权</el-button>
      </div>
      <div :class="addother?'ishidden':'hiddened'">
        <el-button type="primary" id="system_33" @click="addothers">添加内容</el-button>
      </div>
    </el-row>
    <dialog-component
      v-if="showDialog"
      ref="dialogComponent"
      :dialog-title="dialogTitle"
      :item-info="tableItem"
      @closeDialog="closeDialog"
    />
    <dialog-seach
      v-if="showseachDialog"
      ref="dialogSeach"
      :dialog-title="dialogseachTitle"
      :item-info="tableseachItem"
      @closeDialog="closeseachDialog"
    />
    <dialog-addrole
      v-if="roleDialog"
      ref="dialogAddrole"
      :dialog-title="dialogaddroleTitle"
      :item-info="tableaddroleItem"
      @closeDialog="closeaddroleDialog"
    />
    <dialog-addgrade
      v-if="gradeDialog"
      ref="dialogAddgrade"
      :dialog-title="dialogaddgradeTitle"
      :item-info="tableaddgradeItem"
      @closeDialog="closeaddgradeDialog"
    />
    <dialog-addguide
      v-if="guideDialog"
      ref="dialogAddguide"
      :dialog-title="dialogaddguideTitle"
      :item-info="tableaddguideItem"
      @closeDialog="closeaddguideDialog"
    />
    <dialog-addtype
      v-if="typeDialog"
      ref="dialogAddtype"
      :dialog-title="dialogaddtypeTitle"
      :item-info="tableaddtypeItem"
      @closeDialog="closeaddtypeDialog"
    />
    <!-- <dialog-addcont
      v-if="contDialog"
      ref="dialogAddcont"
      :dialog-title="dialogaddcontTitle"
      :item-info="tableaddcontItem"
      @closeDialog="closeaddcontDialog"
    /> -->
    <dialog-seatuser
      v-if="seatuserDialog"
      ref="dialogSeatuser"
      :dialog-title="dialogseatuserTitle"
      :item-info="tableseatuserItem"
      @closeDialog="closeseatuserDialog"
    />
    <dialog-screen
      v-if="screenDialog"
      ref="dialogScreen"
      :dialog-title="dialogscreenTitle"
      :item-info="tablescreenItem"
      @closeDialog="closescreenDialog"
    />
    <dialog-banner
      v-if="bannerDialog"
      ref="dialogBanner"
      :dialog-title="dialogbannerTitle"
      :item-info="tablebannerItem"
      @closeDialog="closebannerDialog"
    />
    <dialog-addother
      v-if="addotherDialog"
      ref="dialogAddother"
      :dialog-title="dialogaddTitle"
      :item-info="tableaddItem"
      @closeDialog="closeaddDialog"
    />
  </div>
</template>

<script>
import DialogComponent from "@/components/Dialog/dialog.vue";
import DialogSeach from "@/components/Dialog/Seachdialog.vue";
import DialogAddrole from "@/components/Dialog/Addroledialog.vue";
import DialogAddgrade from "@/components/Dialog/Addgradedialog.vue";
import DialogAddguide from "@/components/Dialog/Addguidedialog.vue";
// import DialogAddcont from "@/components/Dialog/Addcontdialog.vue";
import DialogAddtype from "@/components/Dialog/Addtypedialog.vue";
import DialogSeatuser from "@/components/Dialog/seatuser.vue";
import DialogScreen from "@/components/Dialog/screen.vue";
import DialogBanner from "@/components/Dialog/Bannerdialog.vue";
import DialogAddother from "@/components/Dialog/Addotherdialog.vue";
import { Addcontent, lists,refreshSession,setMeal } from "@/api/user";
import Base64 from "@/utils/base";
import { getp_id } from "@/utils/getmenuid";

export default {
  inject:["reload"],
  data() {
    return {
      addData: "",
      dialogTitle: "添加客户",
      dialogseachTitle: "客户搜索",
      dialogaddroleTitle: "添加角色",
      dialogaddgradeTitle: "添加充值档次",
      dialogaddguideTitle: "新增帮助",
      // dialogaddcontTitle: "添加内容",
      dialogseatuserTitle: "固定座位用户",
      dialogscreenTitle: "筛选",
      dialogBannerTitle: "添加轮播图",
      dialogAddTitle: "添加",
      dialogaddtypeTitle: "新增类别",
      tableItem: {
     
      },
      index2: "",
      tableseachItem: {
        name: "",
        code: "",
        userId: "",
        status: ""
      },
      tableaddroleItem: {
        rolename: ""
      },
      showDialog: false,
      showseachDialog: false,
      seatuserDialog: false,
      screenDialog:false,
      bannerDialog:false,
      addotherDialog:false,
      roleDialog: false,
      gradeDialog: false,
      guideDialog: false,
      // contDialog: false,
      typeDialog: false,
      levelList: null,
      bool: null,
      packagebool: null,
      shopbool: null,
      storebool:null,
      memberbool: null,
      rechargebool: null,
      guidebool: null,
      typebool: null,
      bannerbool: null,
      refreshmbool: null,
      addother:null,
      systembool:null,
      // targetbool: null
    };
  },
  components: {
    DialogComponent,
    DialogSeach,
    DialogAddrole,
    DialogAddgrade,
    DialogAddguide,
    // DialogAddcont,
    DialogAddtype,
    DialogSeatuser,
    DialogScreen,
    DialogBanner,
    DialogAddother
  },

  watch: {
    $route() {
      this.getBreadcrumb();
    }
  },
  created() {
    this.getBreadcrumb();
    // if (localStorage.getItem("index2")) {
    //   this.shopbool = true;
    // } else {
    //   this.shopbool = false;
    // }
  },
  methods: {
    // 关闭操作
    closeDialog(flag) {
      if (flag) {
        // 重新刷新表格内容
        // setTimeout(() => {
        //   this.fetchData();
        // }, 1000);
      }
      this.showDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogComponent"].showDialog = false;
      });
    },
    // 关闭操作
    closeseachDialog(flag) {
      if (flag) {
        // 重新刷新表格内容
        // setTimeout(() => {
        //   this.fetchData();
        // }, 1000);
      }
      this.showseachDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogSeach"].showseachDialog = false;
      });
    },
    closeaddroleDialog(flag) {
      if (flag) {
      }
      this.roleDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogAddrole"].roleDialog = false;
      });
    },
    closeaddgradeDialog() {
      if (flag) {
      }
      this.gradeDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogAddgrade"].gradeDialog = false;
      });
    },
    closeaddguideDialog() {
      if (flag) {
      }
      this.guideDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogAddguide"].guideDialog = false;
      });
    },
    closeaddtypeDialog() {
      if (flag) {
      }
      this.typeDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogAddtype"].typeDialog = false;
      });
    },
    // closeaddcontDialog() {
    //   if (flag) {
    //   }
    //   this.contDialog = false;
    //   this.$nextTick(() => {
    //     this.$refs["dialogAddcont"].contDialog = false;
    //   });
    // },
    closeseatuserDialog() {
      this.seatuserDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogSeatuser"].seatuserDialog = false;
      });
    },
    closescreenDialog() {
      this.screenDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogScreen"].screenDialog = false;
      });
    },
    handleLink() {
      this.showDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogComponent"].showDialog = true;
      })
      // Addcontent().then(res => {
      //   this.addData = res.result;
      // });
    },
    addrole() {
      this.roleDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogAddrole"].roleDialog = true;
      });
    },
    addgrade() {
      this.gradeDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogAddgrade"].gradeDialog = true;
      });
    },
    addguide() {
      this.guideDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogAddguide"].guideDialog = true;
      });
    },
    addtype() {
      this.typeDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogAddtype"].typeDialog = true;
      });
    },
    // addcont() {
    //   this.contDialog = true;
    //   this.$nextTick(() => {
    //     this.$refs["dialogAddcont"].contDialog = true;
    //   });
    // },
    //新增轮播
    addbannerlist(){
      this.bannerDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogBanner"].bannerDialog = true;
      });
    },
    addothers(){
      this.addotherDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogAddother"].addotherDialog = true;
      });
    },
    closeaddDialog() {
      this.addotherDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogAddother"].addotherDialog = false;
      });
    },
    refreshs(){
      refreshSession().then(res => {
        // console.log(res)
        if(res.status==2){
          this.$message({
            message:res.message,
            type:"warning"
          })
          return
        }
        if(res.status==1){
           this.$message({
            message:res.message,
            type:"success"
          })
          this.reload()
        }
      });
    },
    closebannerDialog() {
      if (flag) {
      }
      this.bannerDialog = false;
      this.$nextTick(() => {
        this.$refs["dialogBanner"].bannerDialog = false;
      });
    },
    addstore(){
      this.$router.push({ path: "/admin/store/storeAdd" });
    },
    handleseach() {
      this.showseachDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogSeach"].showseachDialog = true;
      });
    },
    handseatuser() {
      this.seatuserDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogSeatuser"].seatuserDialog = true;
      });
    },
    addmeal() {
      this.$router.push({ path: "/admin/sell/addMeal" });
    },
    screend(){
      this.screenDialog = true;
      this.$nextTick(() => {
        this.$refs["dialogScreen"].screenDialog = true;
      });
    },
    getBreadcrumb() {
      // let matched = this.$route.matched.filter(
      //   item => item.meta && item.meta.title
      // );
      const first = this.$route;
      if (first.path == "/admin/user/userInfo") {
        this.bool = true;
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
          
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          // localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "user_2") {
              document.getElementById("user_2").style.display = "inline";
            }
            if (item == "user_3") {
              document.getElementById("user_3").style.display = "inline";
            }
          });
        });
      } else {
        this.bool = false;
      }
      if (first.path == "/admin/sell/setMeal") {
        this.packagebool = true;
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
          
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          // localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "sell_15") {
              document.getElementById("sell_15").style.display = "inline";
            }
          });
        })
          // console.log(localStorage.getItem("type_id"))
          // console.log(localStorage.getItem("shop_id"))
        // getsetMeal(page, num) {
      let parmes = {
        store_ids:localStorage.getItem("shop_id")||0,
        type:localStorage.getItem("type_id")||0,
        page: 1,
        limit: 10
      };
      setMeal({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        localStorage.setItem("tableDatas", JSON.stringify(res.result.data));
        localStorage.setItem("totle", JSON.stringify(res.result.count));
        // this.tableDatas = res.result.data;
        // this.totle = res.result.count;
      })
    // }

      } else {
        this.packagebool = false;
        localStorage.removeItem("tableDatas")
        localStorage.removeItem("totle")
        localStorage.removeItem("shop_id")
        localStorage.removeItem("type_id")
      }
      if (first.path == "/admin/store/storeList"&&JSON.parse(localStorage.getItem("storemenu"))[0].id=="") {
        this.storebool = true
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          // localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "store_27") {
              document.getElementById("store_27").style.display = "inline";
            }
          });
        });
      }else{
        this.storebool = false
      }
      if (first.path == "/admin/platRole/list") {
        this.memberbool = true;
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: 33 })) },
          
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "platRole_2") {
              document.getElementById("platRole_2").style.display = "inline";
            }
          });
        });
      } else {
        this.memberbool = false;
      }
      // if (first.path == "/example/tree") {
      //   this.rechargebool = true;
      // } else {
      //   this.rechargebool = false;
      // }
        if (first.path == "/admin/sell/indexs") {
        this.rechargebool = true;
         lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "sell_19") {
              document.getElementById("sell_19").style.display = "inline";
            }
          });
        });
      } else {
        this.rechargebool = false;
      }
      if (first.path == "/admin/system/help") {
        this.guidebool = true;
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
          
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "system_3") {
              document.getElementById("system_3").style.display = "inline";
            }
          });
        });
      } else {
        this.guidebool = false;
      }
      if(first.path == "/admin/system/volksw"){
        this.refreshmbool = true
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "system_35") {
              document.getElementById("system_35").style.display = "inline";
            }
          });
        });
      }else{
        this.refreshmbool = false
      }
      if(first.path == "/admin/system/otherAdd"){
        this.addother = true
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: 120 })) },
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "system_33") {
              document.getElementById("system_33").style.display = "inline";
            }
          });
        });
      }else{
        this.addother = false
      }
      if(first.path == "/admin/sell/sellBusines"){
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          let pagetitle = [];
          let pid = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
            pagetitle.push(v.pc_menu_name);
            pid.push(v.id);
          });
          localStorage.setItem("btnmodel", JSON.stringify([{ btnarr,pagetitle,pid }]));
          // btnarr.forEach(item => {
          //   if (item == "system_3") {
          //     document.getElementById("system_3").style.display = "inline";
          //   }
          // });
        });
      }
      if (first.path == "/admin/system/genre") {
        this.typebool = true;
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
          
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "system_20") {
              document.getElementById("system_20").style.display = "inline";
            }
          });
        });
      } else {
        this.typebool = false;
      }
      if (first.path == "/admin/system/banner") {
        this.bannerbool = true;
        lists(
          { request_data: Base64.encode(JSON.stringify({ pid: getp_id() })) },
          
        ).then(res => {
           if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          localStorage.setItem("btnmodel", JSON.stringify([{ btnarr }]));
          btnarr.forEach(item => {
            if (item == "system_8") {
              document.getElementById("system_8").style.display = "inline";
            }
          });
        });
      } else {
        this.bannerbool = false;
      }
      // if (first.path == "/system/wechatother/target") {
      //   this.targetbool = true;
      // } else {
      //   this.targetbool = false;
      // }
      // if (first.path == "/shop") {
      // } else {
      //   this.shopbool = false;
      // }
      if (!this.isDashboard(first)) {
        matched = [{ path: "/dashboard", meta: { title: "Dashboard" } }].concat(
          matched
        )
      }
      this.levelList = matched.filter(
        item => item.meta && item.meta.title && item.meta.breadcrumb !== false
      )
    },
    isDashboard(route) {
      const name = route && route.name;
      if (!name) {
        return false;
      }
      return (
        name.trim().toLocaleLowerCase() === "Dashboard".toLocaleLowerCase()
      );
    }
  }
};
</script>

<style>
.ishidden {
  margin-right: 20px;
  display: block;
}
.hiddened {
  margin-right: 20px;
  display: none;
}
#system_3 {
  display: none;
}
#sell_19{
  display: none;
}
#sell_15{
  display: none;
}
#system_8{
  display: none;
}
#system_20{
  display: none;
}
#platRole_2{
  display: none;
}
#store_27{
  display: none;
}
#user_2{
  display: none;
}
#user_3{
  display: none;
}
#system_200{
  display: inline;
}
</style>
